package com.gem.demo.controller;

import com.gem.demo.entity.User;
import com.gem.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;


import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class UserController {
     @Autowired
     private UserService userService;

    @RequestMapping("/login")
    public String login(String username, String password, HttpSession session){
        User user=userService.login(username,password);
        if (user==null){
            //登录失败 重新登录 跳转到登录页
        //重定向
            return "redirect:/toLogin";
        }else{
            //登录成功
            //跳转到主页面
            //主页商品Controller
           session.setAttribute("currUser",user);
           return "redirect:/product/index";
        }

    }
}

